import {reqToDoLoginInfo,reqGetuserInfo,reqlogoutInfo} from '@/api/index'
const actions = {
    async userLogin({commit},data){
        let result = await reqToDoLoginInfo(data)
        
        localStorage.setItem('user_token',result.data.token)
        
        if(result.code==200){
            commit('USERLOGIN',result.data)
        }else{
            return Promise.reject(new Error('faile'))
        }
        
    },
    async abc({commit}){
        let result = await reqGetuserInfo()
        console.log(result.data,1)
        if(result.code==200){
            commit("ABC",result.data)
        }else{
            return Promise.reject(new Error('faile'))
        }

    },
    async logout({commit}){
        let result = await reqlogoutInfo()
        if(result.code==200){
            commit('LOGOUT')
            return 'ok'
        }else{
            return Promise.reject(new Error('faile'))
        }

    }

}
const mutations = {
    USERLOGIN(state,value){
        state.token = value.token

    },
    ABC(state,value){
        state.userInfo = value

    },
    LOGOUT(state){
        state.token = ''
        state.userInfo = ''
        localStorage.removeItem('user_token')


    }

}
const state = {
    token:{},
    userInfo:{}
}
export default{
    actions,
    mutations,
    state

}